package com.basic.common.core.domain.entity;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.*;

import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.format.DateTimeFormat;
import com.basic.common.annotation.EnumFiledConvert;
import com.basic.common.utils.easyExcel.ExcelEnumConvert;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import com.basic.common.core.domain.BaseEntity;
import com.basic.common.xss.Xss;

/**
 * 用户对象 sys_user
 * 
 * @author zhaoxy_jn@163.com
 */
@Getter
@Setter
@ExcelIgnoreUnannotated
public class SysUser extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 用户ID */
    @ExcelProperty(value = "用户序号")
    private Long userId;

    /** 部门ID */
    @ExcelProperty(value = "部门编号")
    private Long deptId;

    /** 用户账号 */
    @ExcelProperty(value = "登录名称")
    @Xss(message = "用户账号不能包含脚本字符")
    @NotBlank(message = "用户账号不能为空")
    @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
    private String userName;

    /** 用户昵称 */
    @ExcelProperty(value = "用户名称")
    @Xss(message = "用户昵称不能包含脚本字符")
    @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
    private String nickName;

    /** 用户编号 */
    @ExcelProperty(value = "用户编号")
    @Xss(message = "用户编号不能包含脚本字符")
    @NotBlank(message = "用户编号不能为空")
    @Size(min = 0, max = 30, message = "用户编号长度不能超过30个字符")
    private String userCode;

    /** 用户邮箱 */
    @ExcelProperty(value = "用户邮箱")
    @Email(message = "邮箱格式不正确")
    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    private String email;

    /** 手机号码 */
    @ExcelProperty(value = "手机号码")
    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    private String phoneNumber;

    /** 用户性别 */
    @ExcelProperty(value = "用户性别", converter = ExcelEnumConvert.class)
    @EnumFiledConvert(enumMap = "0=男,1=女,2=未知")
    private String sex;

    /** 用户头像 */
    private String avatar;

    /** 密码 */
    private String password;

    /** 帐号状态（0正常 1停用） */
    @ExcelProperty(value = "帐号状态", converter = ExcelEnumConvert.class)
    @EnumFiledConvert(enumMap = "0=正常,1=停用")
    private String status;

    /** 入职日期 */
    @ExcelProperty(value = "入职日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat("yyyy-MM-dd")
    private Date serviceDate;

    /** 离职日期 */
    @ExcelProperty(value = "离职日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat("yyyy-MM-dd")
    private Date terminationDate;

    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    /** 最后登录IP */
    @ExcelProperty(value = "最后登录IP")
    private String loginIp;

    /** 最后登录时间 */
    @ExcelProperty(value = "最后登录时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    private Date loginDate;

    
    private SysDept dept;

    /** 角色对象 */
    private List<SysRole> roles;

    /** 角色组 */
    private Long[] roleIds;

    /** 岗位组 */
    private Long[] postIds;

    /** 角色ID */
    private Long roleId;

    public SysUser()
    {

    }

    public SysUser(Long userId)
    {
        this.userId = userId;
    }

    public boolean isAdmin()
    {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId)
    {
        return userId != null && 1L == userId;
    }

    @Override
    public String toString() {
        return "SysUser{" +
                "userId=" + userId +
                ", deptId=" + deptId +
                ", userName='" + userName + '\'' +
                ", nickName='" + nickName + '\'' +
                ", userCode='" + userCode + '\'' +
                ", email='" + email + '\'' +
                ", phoneNumber='" + phoneNumber + '\'' +
                ", sex='" + sex + '\'' +
                ", avatar='" + avatar + '\'' +
                ", password='" + password + '\'' +
                ", status='" + status + '\'' +
                ", serviceDate=" + serviceDate +
                ", terminationDate=" + terminationDate +
                ", delFlag='" + delFlag + '\'' +
                ", loginIp='" + loginIp + '\'' +
                ", loginDate=" + loginDate +
                ", dept=" + dept +
                ", roles=" + roles +
                ", roleIds=" + Arrays.toString(roleIds) +
                ", postIds=" + Arrays.toString(postIds) +
                ", roleId=" + roleId +
                '}';
    }
}
